<template>
       <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady" 
          style="height:100%" class='ag-theme-alpine'
          :defaultColDef="defaultColDef" :rowData="table.dataList" 
          :columnDefs="cfsValue" :localeText="localeTextData"/>
    <paginationCopys :total="total" show-total show-jumper 
        show-page-size @change="changePage"  @page-size-change="changeSize" 
        style="justify-content: center;margin-top: 10px;"  :page-size="pagination.pageSize"
        :current="pagination.page" />
</template>

<script  lang="ts">
    
    import emitter from "@/hooks/useEventBus";
    import { localeText } from '@/api/aggridZw'
    import { onMounted,reactive, ref } from 'vue';
    import { assTable } from '@/utils/assemblyLevelTable';
    import { Message } from '@arco-design/web-vue';
    import { usePagination, useTable } from '@/hooks/table';
   export default {
      name:'processed',
      components: {  },
       props:{
            searchData:{
                type:Object,
                default:() => {}
            }
       },
      setup(){
        const table = useTable();
        emitter.on("refresh-untreated", () => {
            pagination.page = 1;
            doRefresh();
        });
        const doRefresh = () => {};
        const editHandler = (data:any) => {

        };
        const checkDetail = (data:any) => {

        };
        const delHeader = (data:any) => {

        };
        const pagination = usePagination(doRefresh);
        //表格方面
        const gridOption = ref();
        const gridReady = (params:any) => {
          gridOption.value = params.api; 
          //调整表格自适应大小
        }
        const defaultColDef = {
            sortable: true,
            resizable: true,
            filter: true,
            width: 150
        };
        let cfsValue:any = [
            {
                headerName: "流转卡号",    
                field: "circulatCard",
            },
            {
                headerName: "客户名称",    
                field: "circulatCard",
            },
            {
                headerName: "退货单号",    
                field: "circulatCard",
            },
            {
                headerName: "收料单号",    
                field: "circulatCard",
            },
            {
                headerName: "送货单位",    
                field: "circulatCard",
            },
            {
                headerName: "织造序号",    
                field: "circulatCard",
            },
            {
                headerName: "布号",    
                field: "circulatCard",
            },
            {
                headerName: "品名",    
                field: "circulatCard",
            },
            {
                headerName: "色称",    
                field: "circulatCard",
            },
            {
                headerName: "计划单号",    
                field: "circulatCard",
            },
            {
                headerName: "纱支",    
                field: "circulatCard",
            },
            {
                headerName: "门幅",    
                field: "circulatCard",
            },
            {
                headerName: "克重",    
                field: "circulatCard",
            },
            {
                headerName: "尺寸",    
                field: "circulatCard",
            },
            {
                headerName: "退货匹数",    
                field: "circulatCard",
            },
            {
                headerName: "退货重量",    
                field: "circulatCard",
            },
            {
                headerName: "库位",    
                field: "circulatCard",
            },
            {
                headerName: "托盘编号",    
                field: "circulatCard",
            },
            {
                headerName: "纱批",    
                field: "circulatCard",
            },
            {
                headerName: "单位",    
                field: "circulatCard",
            },
            {
                headerName: "金额",    
                field: "circulatCard",
            },
            {
                headerName:'操作',   
                lockPosition:'right',
                sortable:false,
                resizable:false,
                filter:false,
                width:150,
                cellRenderer:{
                    template:`
                       <a-tag color="#eec216" @click="a" class="gesture">修改</a-tag>
                       <a-tag color="#00d223" @click="b" class="gesture">明细</a-tag>
                       <a-tag color="#ee1633" @click="c" class="gesture">删除</a-tag>
                    `,
                    setup(props:any) {
                         const a = () => {
                            editHandler(props.params.data);
                         }; 
                         const b = () => {
                            checkDetail(props.params.data);
                         };
                         const c = () => {
                            delHeader(props.params.data);
                         }; 
                         return {
                            a,b,c
                         }
                    }
                }
            },
        ];

        let a = [{
                showRowGroup: 'hide_def',
                "headerName": "",
                "checkboxSelection": true,
                "headerCheckboxSelection": true,
                "pinned": "left",
                "width": 50,
                resizable: false,
                filter: false,
                sortable: false,
                minWidth: 50,
                maxWidth: 50,
                lockPosition: "left",
            }]
            cfsValue = a.concat(cfsValue);
            const total = ref(10);
            const changePage = (val:any) => {
                pagination.page = val
                doRefresh();
            }
            const changeSize = (val:any) => {
                pagination.pageSize = val
                doRefresh();
            }

            const localeTextData :any = ref(localeText);
            emitter.on('export-processed',() => { 
                let selectList = gridOption.value.getSelectedRows();
                // console.log(selectList);
                if (selectList.length === 0) {
                    Message.error('请勾选需要导出的数据')
                    return
                } else {
                    //导出数据
                    let nowRow = table.dataList.filter(function (o) {
                        return (gridOption.value.getSelectedRows().map((o: any) => { return o.id })).indexOf(o["id"]) !== -1;
                    })
                    assTable(cfsValue,nowRow,'车间退库信息(已处理)');
                }
            });
            return {
                pagination,
                table,
                localeTextData,
                changePage,
                changeSize,
                total,
                cfsValue,
                defaultColDef,
                gridReady,
            }
      }
   }
</script>

<style scoped>

</style>